//
//  ZYCProfileSettingViewController.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/20.
//

#import "ZYCProfileSettingViewController.h"
#import "ZYCProfileSettingCell.h"
#import "ZYCSettingNewsPushViewController.h"
#import "ZYCSettingLanguageViewController.h"
#import "ZYCSettingManageStorageViewController.h"
@interface ZYCProfileSettingViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataSource;
@end

@implementation ZYCProfileSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = NSLocalizedString(@"设置", nil);
    [self.view addSubview:self.tableView];
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataSource.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZYCProfileSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ZYCProfileSettingCell class]) forIndexPath:indexPath];
    cell.titleString = self.dataSource[indexPath.section][@"title"];
    return cell;
}
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 20;
    }
    return 5;;
}

-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 55.0f;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    [self pushViewControllerWithName:self.dataSource[indexPath.section][@"clsName"]];
}
- (void)pushViewControllerWithName:(NSString *)viewControllerName{
    Class className = NSClassFromString(viewControllerName);
    if (className) {
        ZYCBaseViewController *viewController = [[className alloc] init];
        [self.navigationController pushViewController:viewController animated:YES];
    }
}


- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight ) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerClass:[ZYCProfileSettingCell class] forCellReuseIdentifier:NSStringFromClass([ZYCProfileSettingCell class])];
    }
    return _tableView;
}

- (NSArray *)dataSource {
    if (!_dataSource) {
        _dataSource = @[
//                        @{
//                            @"title":@"消息推送设置",@"clsName":@"ZYCSettingNewsPushViewController"
//                            
//                        },
                        @{
                            @"title":@"版本说明",@"clsName":@"ZYCSettingVersonDescriptionsViewController"
                            
                        },
                        @{
                            @"title":@"帮助中心",@"clsName":@"ZYCSettingHelpCenterViewController"
                            
                        }
                        ];
    }
    return _dataSource;
}

//- (NSArray *)dataSource {
//    if (!_dataSource) {
//        _dataSource = @[
//                        @{@"title":@"消息推送设置",@"clsName":@"ZYCSettingNewsPushViewController"},
//                        @{@"title":@"语言设置",@"clsName":@"ZYCSettingLanguageViewController"},
//                        @{@"title":@"管理存储空间",@"clsName":@"ZYCSettingManageStorageViewController"},
//                        @{@"title":@"版本说明",@"clsName":@"ZYCSettingVersonDescriptionsViewController"},
//                        @{@"title":@"帮助中心",@"clsName":@"ZYCSettingHelpCenterViewController"}
//                        ];
//    }
//    return _dataSource;
//}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
